home *** CD-ROM | disk | FTP | other *** search
- #
- # help.test
- #
- # Tests for the help subsystem. Help must be build first. If help files
- # change, thest tests may have to be changed.
- #---------------------------------------------------------------------------
- # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: help.test,v 3.1 1994/01/23 16:58:20 markd Exp $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] != "test"} then {source testlib.tcl}
-
- #
- # Only run help test if help has been installed.
- #
- if {"[glob -nocomplain ../tclmaster/help/*]" == ""} {
- echo "****"
- echo "**** No help pages in tclmaster/help - help test not run"
- echo "****"
- return
- }
-
- #
- # Fork without exec will not work under Tk, skip this test
- #
- if ![lempty [info commands button]] {
- puts stderr "*************************************************************"
- puts stderr "Help tests are constructed in a way that does not work"
- puts stderr "under Tk. Test skipped."
- puts stderr "*************************************************************"
- puts stderr ""
- return
- }
-
- #------------------------------------------------------------------------------
- # Read a line from the server, set an alarm to make sure it doesn't hang.
- proc ReadServer {} {
- global G_helpOutPipeFH
-
- alarm 45
- if {[gets $G_helpOutPipeFH line] < 0} {
- alarm 0
- error "EOF from help server"}
- alarm 0
- return $line
- }
-
- #------------------------------------------------------------------------------
- # Eat a prompt line from the help server.
-
- proc EatServerPrompt {} {
- set line [ReadServer]
- if {"$line" != "===HELPSERVER==="} {
- error "unexpected output from help server: `$line'"}
- }
-
- #------------------------------------------------------------------------------
- # Send a command to the help server and return the output. The help server
- # output will be bracketed with commands to mark the beginning and ending.
- # An extra newline is always queued to continue the help pager. The prompt of
- # the pager will be removed from the output. This assumes that the output has
- # no lines starting with `:'.
- #
- proc HelpSend {cmd pagerCntVar} {
- global G_helpInPipeFH G_helpOutPipeFH
- upvar $pagerCntVar pagerCnt
-
- puts $G_helpInPipeFH $cmd
- puts $G_helpInPipeFH "" ;# Just a new line..
- flush $G_helpInPipeFH
-
- set pagerCnt 0
- set results {}
-
- # Read lines of the output.
- while 1 {
- set line [ReadServer]
- if {"[cindex $line 0]" == ":"} {
- set line [crange $line 1 end]
- incr pagerCnt
- puts $G_helpInPipeFH "" ;# Just a new line
- }
- if {"$line" == "===HELPSERVER==="} {
- break}
- append results $line "\n"
- }
- # Eat the extra prompt caused by the typed-ahead newline
- EatServerPrompt
-
- return $results
- }
- #
- # Create the help server process, which will execute the commands,
- # with stdin and stdout redirected to pipes.
- #
-
- global G_helpInPipeFH G_helpOutPipeFH G_helpPid
-
- pipe fromClientPipeFH G_helpInPipeFH
- pipe G_helpOutPipeFH toClientPipeFH
-
- fcntl $G_helpInPipeFH NOBUF 1
- fcntl $G_helpOutPipeFH NOBUF 1
-
- flush stdout ;# Not going to exec, must clean up the buffers.
- flush stderr
- set G_helpPid [fork]
-
- if {$G_helpPid == 0} {
- close stdin
- dup $fromClientPipeFH stdin
- close stdout
- dup $toClientPipeFH stdout
- close $G_helpInPipeFH
- close $G_helpOutPipeFH
-
- eval $SAVED_UNKNOWN
-
- commandloop {puts stdout "===HELPSERVER==="; flush stdout} \
- {error "Help server incomplete cmd"}
- error "Help server got eof"
- }
-
- close $fromClientPipeFH
- close $toClientPipeFH
-
- #
- # An alarm will be set when talking to the server uncase it doesn't talk back
- #
- signal error SIGALRM
-
- # Nuke the first prompt
- EatServerPrompt
-
- # Now run the tests.
-
-
- Test help-1.1 {help tests} {
- HelpSend "help" promptCnt
- } 0 {
- Subjects available in /:
- tcl/
-
- Help pages available in /:
- help
- }
-
- Test help-1.1.1 {help tests} {
- HelpSend "help tcl" promptCnt
- } 0 {
- Subjects available in /tcl:
- control/ debug/ files/ filescan/
- internation/ intro/ keyedlists/ libraries/
- lists/ math/ processes/ signals/
- status/ strings/ tclshell/ time/
- variables/
- }
-
- Test help-1.2 {help tests} {
- HelpSend "helppwd" promptCnt
- } 0 {Current help subject: /
- }
-
- Test help-1.3 {help tests} {
- HelpSend "helpcd tcl/filescan" promptCnt
- } 0 {}
-
- Test help-1.4 {help tests} {
- HelpSend "helppwd" promptCnt
- } 0 {Current help subject: /tcl/filescan
- }
-
- Test help-1.5 {help tests} {
- set result [HelpSend "help /tcl/lists/lassign" promptCnt]
- set fh [open "../tclmaster/help/tcl/lists/lassign"]
- set expect [read $fh]
- close $fh
- set summary {}
- if {"$expect" == "$result"} {
- append summary "CORRECT"
- } else {
- append summary "DATA DOES NOT MATCH : $result"
- }
- if {$promptCnt == 0} {
- append summary " : PROMPT OK"
- } else {
- append summary " : TOO MANY PROMPTS: $promptCnt"
- }
- set summary
- } 0 {CORRECT : PROMPT OK}
-
- Test help-1.6 {help tests} {
- set result [HelpSend "help /tcl/math/expr" promptCnt]
- set fh [open "../tclmaster/help/tcl/math/expr"]
- set expect [read $fh]
- close $fh
- set summary {}
- if {"$expect" == "$result"} {
- append summary "CORRECT"
- } else {
- append summary "DATA DOES NOT MATCH: $result"
- }
- if {$promptCnt >= 2} {
- append summary " : PROMPT OK"
- } else {
- append summary " : NOT ENOUGH PROMPTS: $promptCnt"
- }
- set summary
- } 0 {CORRECT : PROMPT OK}
-
- Test help-1.7 {help tests} {
- HelpSend "apropos upvar" promptCnt
- } 0 {tcl/variables/upvar - Create link to variable in a different stack frame
- }
-
- Test help-1.8 {help tests} {
- HelpSend "apropos clock" promptCnt
- } 0 {tcl/time/alarm - Set a process alarm clock.
- tcl/time/convertclock - Parse and convert a date and time string to integer clock value.
- tcl/time/fmtclock - Convert an integer time value to human-readable format.
- tcl/time/getclock - Return current date and time as an integer value.
- }
-
- Test help-1.9 {help tests} {
- HelpSend "helpcd" promptCnt
- } 0 {}
-
- Test help-1.10 {help tests} {
- HelpSend "helppwd" promptCnt
- } 0 {Current help subject: /
- }
-
-
- # Terminate the help server.
-
- puts $G_helpInPipeFH "exit 0"
- set status [wait $G_helpPid]
- if {"$status" != "$G_helpPid EXIT 0"} {
- error "Bad status returned: `$status'"}
-
- return
-